#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
@file_name: asyc_timed.py
@date: 2025-07-28 14:38
@author: Falling Snow
@desc: async 计时装饰器
"""

import functools
import time
from typing import Callable, Any


def async_timed():
    def wrapper(fn: Callable) -> Callable:
        @functools.wraps(fn)
        async def wrapped(*args, **kwargs) -> Any:
            print(f"调用{fn.__name__}函数, 传递的参数为{args}, {kwargs}")
            start = time.time()
            try:
                return await fn(*args, **kwargs)

            finally:
                end = time.time()
                print(f"执行 {fn.__name__} 耗费 {(end - start):.4f} 秒")

        return wrapped

    return wrapper
